﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlTypes;
using System.ComponentModel;

namespace SqlTypeToFramerworkType
{
    public static class SqlTypeToFrameworkType
    {
        static private string GetDate(DateTime dateTime)
        {
            return String.Format("{0}.{1}.{2}", GetWithTwoDigits(dateTime.Day), GetWithTwoDigits(dateTime.Month), dateTime.Year);
        }
        static private string GetTime(TimeSpan timeSpan)
        {
            return String.Format("{0}:{1}:{2}", GetWithTwoDigits(timeSpan.Hours), GetWithTwoDigits(timeSpan.Minutes), GetWithTwoDigits(timeSpan.Seconds));
        }
        static private string GetWithTwoDigits(int num)
        {
            if (num >= 0 && num <= 9)
                return String.Format("0{0}", num);
            else
                if (num >= 10 && num <= 59)
                    return num.ToString();
            throw new Exception();
        }        
        public static string GetExcelFormatByType(string type)
        {
            try
            {
                switch (type)
                {
                    case "smalldatetime":
                        return "dd/mm/yyyy hh:mm:ss";
                    case "datetime":
                        return "dd/mm/yyyy hh:mm:ss";
                    case "date":
                        return "dd/mm/yyyy";
                    case "bit":
                        return "0";
                    case "tinyint":
                        return "0";
                    case "smallint":
                        return "0";
                    case "numeric":
                        return "0";
                    case "int":
                        return "0";
                    case "bigint":
                        return "0";
                    case "binary":
                        return "0";
                    case "decimal":
                        return "0";
                    case "float": case "real":
                        return "0.00";
                     case "money":
                        return "0.00";
                    case "smallmoney":
                        return "0.00";
                    case "char": case "nchar": case "nvarchar": case "varchar":
                        return "@";
                    case "text": case "ntext":
                        return "@";
                    case "timestamp":
                        return "@";
                    case "uniqueidentifier":
                        return "@";
                    case "xml":
                        return "@";
                    default:
                        throw new ArgumentException();
                        break;
                }
            }
            catch (NullReferenceException ex)
            {
                throw ex;
            }
        }
    }
}
